package com.ruoyi.project.yingyu.transferorder.service.impl;

import java.util.List;

import javax.annotation.PostConstruct;

import com.alibaba.druid.util.StringUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MoneyUtil;
import com.ruoyi.common.utils.security.ShiroUtils;

import org.hibernate.validator.constraints.ParameterScriptAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.yingyu.transferorder.mapper.TransferOrderMapper;
import com.ruoyi.project.yingyu.transferorder.domain.TransferOrder;
import com.ruoyi.project.yingyu.transferorder.service.ITransferOrderService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 转帐订单Service业务层处理
 * 
 * @author shixiangwen
 * @date 2020-02-17
 */
@Service
public class TransferOrderServiceImpl implements ITransferOrderService {
	@Autowired
	private TransferOrderMapper transferOrderMapper;

	/**
	 * 查询转帐订单
	 * 
	 * @param id 转帐订单ID
	 * @return 转帐订单
	 */
	@Override
	public TransferOrder selectTransferOrderById(Long id) {
		return transferOrderMapper.selectTransferOrderById(id);
	}

	/**
	 * 查询转帐订单列表
	 * 
	 * @param transferOrder 转帐订单
	 * @return 转帐订单
	 */
	@Override
	public List<TransferOrder> selectTransferOrderList(TransferOrder transferOrder) {
		List<TransferOrder> orders = transferOrderMapper.selectTransferOrderList(transferOrder);
		orders.forEach(item -> {
			item.setYuan(MoneyUtil.fee2yuan(item.getFee()).toString());
		});
		return orders;
	}

	/**
	 * 新增转帐订单
	 * 
	 * @param transferOrder 转帐订单
	 * @return 结果
	 */
	@Override
	public int insertTransferOrder(TransferOrder transferOrder) {
		transferOrder.setCreateTime(DateUtils.getNowDate());
		return transferOrderMapper.insertTransferOrder(transferOrder);
	}

	/**
	 * 修改转帐订单
	 * 
	 * @param transferOrder 转帐订单
	 * @return 结果
	 */
	@Override
	public int updateTransferOrder(TransferOrder transferOrder) {
		transferOrder.setUpdateTime(DateUtils.getNowDate());
		return transferOrderMapper.updateTransferOrder(transferOrder);
	}

	/**
	 * 删除转帐订单对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteTransferOrderByIds(String ids) {
		return transferOrderMapper.deleteTransferOrderByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除转帐订单信息
	 * 
	 * @param id 转帐订单ID
	 * @return 结果
	 */
	@Override
	public int deleteTransferOrderById(Long id) {
		return transferOrderMapper.deleteTransferOrderById(id);
	}

}
